 import Vue from 'vue'
import Router from 'vue-router'

const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
    return routerPush.call(this, location).catch(error => error)
}

Vue.use(Router)

export default new Router({
    // mode: 'history',
    routes: [
        {
            path: '/',
            name: 'index',
            component: () => import('@/view/dormitory/Dormitory'),
        },
        {
            path: '/login',
            name: 'login',
            component: () => import('@/view/login/Login'),
        },
        {
            path: '/dormitory',
            name: 'dormitory',
            component: () => import('@/view/dormitory/Dormitory'),//指定了相同的webpackChunkName，会合并打包成y一个js文件
            children: [
                {
                    path: 'home',
                    name: 'home',
                    component: resolve => require(['@/view/dormitory/home/Home'], resolve)//按需加载，一个组件生成一个js文件
                },
                {
                    path: 'manage',
                    name: 'manage',
                    component: resolve => require(['@/view/dormitory/manage/Manage'], resolve),
                    children: [
                        {
                            path: 'building',
                            name: 'building',
                            component: resolve => require(['@/view/dormitory/manage/building/Building'], resolve)
                        },
                        {
                            path: 'room',
                            name: 'room',
                            component: resolve => require(['@/view/dormitory/manage/room/Room'], resolve)
                        },
                    ]
                },
                {
                    path: 'repair',
                    name: 'repair',
                    component: resolve => require(['@/view/dormitory/repair/Repair'], resolve)
                },
                {
                    path: 'cms',
                    name: 'cms',
                    component: resolve => require(['@/view/dormitory/cms/Cms'], resolve)
                },
                {
                    path: 'system',
                    name: 'system',
                    component: () => import('@/view/dormitory/system/System'),
                    children: [

                        {
                            path: 'org',
                            name: 'org',
                            component: resolve => require(['@/view/dormitory/system/org/Org'], resolve)
                        },
                        {
                            path: 'user',
                            name: 'user',
                            component: resolve => require(['@/view/dormitory/system/user/User'], resolve)
                        },
                        {
                            path: 'role',
                            name: 'role',
                            component: resolve => require(['@/view/dormitory/system/role/Role'], resolve)
                        },
                        {
                            path: 'menu',
                            name: 'menu',
                            component: resolve => require(['@/view/dormitory/system/menu/Menu'], resolve)
                        },
                        {
                            path: 'permission',
                            name: 'permission',
                            component: resolve => require(['@/view/dormitory/system/permission/Permission'], resolve)
                        },
                        {
                            path: 'info',
                            name: 'info',
                            component: resolve => require(['@/view/dormitory/system/info/Info'], resolve)
                        },
                        {
                            path: 'session',
                            name: 'session',
                            component: resolve => require(['@/view/dormitory/system/session/Session'], resolve)
                        },
                        {
                            path: 'personal',
                            name: 'personal',
                            component: resolve => require(['@/view/dormitory/system/personal/Personal'], resolve)
                        },
                        {
                            path: 'dict',
                            name: 'dict',
                            component: resolve => require(['@/view/dormitory/system/dict/Dict'], resolve)
                        }
                    ]
                },
                {
                    path: 'daily',
                    name: 'daily',
                    component: resolve => require(['@/view/dormitory/daily/Daily'], resolve),
                    children: [
                        {
                            path: 'visitor',
                            name: 'visitor',
                            component: resolve => require(['@/view/dormitory/daily/visitor/Visitor'], resolve)
                        },
                        {
                            path: 'application',
                            name: 'application',
                            component: resolve => require(['@/view/dormitory/daily/application/Application'], resolve)
                        },
                        {
                            path: 'sanitation',
                            name: 'sanitation',
                            component: resolve => require(['@/view/dormitory/daily/sanitation/Sanitation'], resolve)
                        }
                    ]
                },
            ]
        },
        {
            path: '*',
            redirect: '/'
        }
    ]
})
